package com.concise.appapi.service;

import com.concise.appapi.service.model.TheArticleListsModel;
import com.initialize.pub.dao.ArticleDAO;
import com.initialize.pub.dao.VSearchDAO;
import com.initialize.pub.generate.pojo.VSearch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: jane
 * Date: 2020/3/7
 * Time: 2:53 下午
 * Description:
 */
@Service
public class SearchService {

    @Autowired
    ArticleDAO articleDAO;

    @Autowired
    VSearchDAO vSearchDAO;


    public List<TheArticleListsModel> homeSearch(String key) {
        Collection<VSearch> vSearches = vSearchDAO.selByKey(key);
        return getTheArticleListsModels(vSearches);
    }


    private List<TheArticleListsModel> getTheArticleListsModels(Collection<VSearch> vSearches) {
        List<TheArticleListsModel> articleListsModels = new ArrayList<>();
        for (VSearch vSearch : vSearches) {
            TheArticleListsModel theArticleListsModel = TheArticleListsModel.builder()
                    .aid(vSearch.getAid())
                    .briefContent(vSearch.getContent())
                    .browseTheNumber(vSearch.getBrowseTheNumber())
                    .theTitle(vSearch.getTitle())
                    .thumbUpFor(vSearch.getThumbUpNumber())
                    .updateTime(vSearch.getUpdateTime())
                    .build();
            articleListsModels.add(theArticleListsModel);
        }
        return articleListsModels;
    }
}